package com.ug_project.views

import android.view.View
import android.widget.AdapterView
import android.widget.Spinner

/**
 * Created by yeganaaa on 5/10/2017 : 3:11 AM.
 */

class OnItemSelectedeListener : AdapterView.OnItemSelectedListener {
    var _onSelected: ((position: Int) -> Unit)? = null
    override fun onNothingSelected(parent: AdapterView<*>?) {

    }

    override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
        _onSelected?.invoke(position)
    }

    fun onSelected(listener: (position: Int) -> Unit) {
        _onSelected = listener
    }

}

fun Spinner.selectedListener(action: OnItemSelectedeListener.() -> Unit) {
    onItemSelectedListener = OnItemSelectedeListener().apply(action)
}